

<style>
    #auto{    color: #fff;
        background-color: #3bb4f2;
        border-color: #3bb4f2;}
    .unuse{background-color: #9ca5af!important;border-color:#9ca5af!important;}
    .red {color:red}

</style>


<div class="admin-biaogelist">

    <div class="listbiaoti am-cf">
        <ul class="am-icon-flag on"> <?php  echo $this->address; ?>    </ul>

        <ul style="margin-left: 200px;">任务池剩余单量：<?php  echo $this->poolnub2; ?></ul>

        <dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">拼多多接单</a></dl>

        <!--<dl>
          <button type="button" class="am-btn am-btn-danger am-round am-btn-xs am-icon-plus" > 补充线订单</button>
        </dl>-->
        <!--这里打开的是新页面-->

    </div>

    <div class="fbneirong">



        <form class="am-form jdtask">


            <img src="" width="350px;" height="350px;"  class="picurl" style=" display: none; position: absolute;  left: 800px;  top: 200px;">

            <div class="am-form-group am-cf">

                <input type="hidden" name="id" value="">
                <div id="Pagination" style="margin:20px auto" style="display:none"></div>
                <div class="zuo">获取任务数量：</div>
                <div class="you" style="width: 300px;">
                    <input type="number" class="am-input-sm"  name="epage"   placeholder="获取数量（1-15）">
                </div>
                <div    id="updata" class="am-btn am-btn-secondary am-radius">获取任务</div>
           <!--     <div    id="auto" class="am-btn  am-radius unuse">自动获取</div>-->
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">标题：</div>
                <div class="you">
                    <input type="text"   name="goods_name" class="am-input-sm"  style="width: 500px" id="doc-ipt-email-1" disabled placeholder="请输入标题">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">店铺名：</div>
                <div class="you">
                    <input type="text"   name="shop_name" class="am-input-sm"   style="width: 500px"  id="doc-ipt-email-1" disabled placeholder="请获取店铺名">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="zuo">显示价格：</div>
                <div class="you">
                    <input type="text"   name="price" class="am-input-sm"  style="width: 500px"  id="doc-ipt-email-1"  disabled placeholder="请输入价格">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">商品链接：</div>
                <div class="you">
                    <input type="text"    name="link" class="am-input-sm" id="doc-ipt-email-1"  style="width: 500px"    placeholder="请输入商品链接">
                    <div    style="margin-left: 0px;"  class="fangwen  am-btn am-btn-secondary am-radius"><a href="" target="_Blank">访问</a></div>

                </div>

            </div>

            <div class="am-form-group am-cf">

                <div class="zuo">购买件数：</div>
                <div class="zuo">
                    <input type="text"   name="number" class="am-input-sm" id="doc-ipt-email-1" disabled  style="color: red; font-size: 18px;"  placeholder="请输入件数">
                </div>



              <!--  <div class="zuo">购买SKU：</div>
                <div class="zuo">
                    <input type="text"   name="sku" class="am-input-sm" id="doc-ipt-email-1"  disabled  placeholder="请输入SKU">
                </div>-->



            </div>

            <div class="am-form-group am-cf">

                <div class="zuo">开团价格：</div>
                <div class="zuo">
                    <input type="text"   name="single_price" class="am-input-sm"  disabled  value="" id="doc-ipt-email-1" placeholder="请输入开团价格">
                </div>

                <div class="zuo">拼团价格：</div>
                <div class="zuo">
                    <input type="text"   name="group_price" class="am-input-sm"   disabled value="" id="doc-ipt-email-1" placeholder="请输入拼团价格">
                </div>

            </div>
            <div class="am-form-group am-cf">
                <div class="zuo">购买类型选择：</div>
                <div class="you" style="margin-top: 4px;">
                    <label class="am-radio-inline">
                        <input type="radio"  value="1"   name="pay_type"> 全部开团
                    </label>
                    <label class="am-radio-inline" >
                        <input type="radio" value="2"   name="pay_type"> 单独购买
                    </label>
                    <label class="am-radio-inline" >
                        <input type="radio" value="3"   name="pay_type" > 优先参团
                    </label>
                    <!-- <div class="zuo">SKU：</div>
                     <div class="zuo">
                         <input type="text"   name="sku" class="am-input-sm" id="doc-ipt-email-1" placeholder="请输入SKU">
                     </div>-->

                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">付款总额：</div>
                <div class="zuo">
                    <input type="text" name="allmoney" class="am-input-sm" id="doc-ipt-email-1" style="color: red; font-size: 18px;"  disabled placeholder="请输入付款总额">
                </div>
                <div class="zuo">搜索关键词：</div>
                <div class="zuo">
                    <input type="text"   name="keyword" class="am-input-sm" id="doc-ipt-email-1"   style="width: 700px;" placeholder="请输入关键词">
                </div>
            </div>



            <div class="am-form-group am-cf">
                <div class="zuo">sku：</div>
                <div class="you">
                    <input type="text"   name="sku" class="am-input-sm" id="doc-ipt-email-1"  disabled   placeholder="SKU">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">备注：</div>
                <div class="you">
                    <input type="text"   name="remarks" class="am-input-sm" id="doc-ipt-email-1"  disabled   placeholder="备注">
                </div>
            </div>

            <div class="am-form-group am-cf">
                <div class="zuo">实际付款价格：</div>
                <div class="zuo">
                    <input type="text"   name="real_price" class="am-input-sm" id="doc-ipt-email-1"  autocomplete="off"  placeholder="实际付款价格">
                </div>

                <div class="zuo">awz标识：</div>
                <div class="zuo">
                    <input type="text"   name="awz" class="am-input-sm" id="doc-ipt-email-1"  autocomplete="off"  placeholder="请输入awz">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="zuo">订单号：</div>
                <div class="you">
                    <input type="text"   name="orderid" class="am-input-sm" id="doc-ipt-email-1"  maxlength="22"   autocomplete="off" value="" placeholder="请输入商品订单号">
                </div>
            </div>
            <div class="am-form-group am-cf">
                <div class="you" style="margin-left: 11%;">
                    <div    id="finish"  style="margin-left: 50px;"  class="am-btn am-btn-secondary am-radius">提交任务</div>
                    <div    id="replace" style="margin-left: 200px;"  class="am-btn am-btn-secondary am-radius">替换任务</div>
                    <div    id="throwtask" style="margin-left: 200px;"  class="am-btn am-btn-secondary am-radius">放弃任务</div>


                </div>
            </div>
        </form>



    </div>



    <script>
        var taskste='';
        var on_request=false;
        var type=1;
        var page=1;
        var log="<?php  echo $awz; ?>";
        var date="<?php  echo date('ymd'); ?>-";

        log=log*1;
        var awz="0";
        if(log>0){
            getjdtask(1);
            $("#updata").attr("disabled",'true');
        }
        $("#updata").click(function () {
            getjdtask();
        });

        $("#auto").click(function () {
            if(log>0){
                auto=0;
                $("#auto").addClass("unuse");
                return;
            }
            if(auto==0){
                auto=1;
                $("#auto").removeClass("unuse");
                loop();
            }else{
                auto=0;
                $("#auto").addClass("unuse");
            }

        });

        function loop(){
            if(auto!=0 && log<=0){
                getjdtask(2);
                setTimeout("loop()", 1000);
            }
        }




        function getjdtask(hastask) {
            if (on_request) {
               //alert("等待");
                //return;
            }
            if(hastask!=1){
               /* var newawz =prompt("请输入您的awz标示");
                if(newawz=='' ||newawz==null){
                    alert("awz不能为空");return;
                }*/
            }
            var newawz="";
            var url = "<?php echo base_url(); ?>Hunter/getpddtaskaction";
            var epage=$("input[name='epage']").val();
            if(epage==""){
                epage=15;
            }
            if(epage<6){
                epage=15
            }




            var postdata = {
                'awz': newawz,
                'page': page,
                'epage': epage
            };
            awz=newawz;
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if(data.code==0){
                    $("input[name='epage']").val(data.count);
                    setlisthtnml(data,page);
                    log=data.count;
                    setPagination("Pagination", data.count, page, 1, function (clickPage) {
                        page = parseInt(clickPage) + 1;
                        showtask(page);
                    });
                 }else{
                    layer.msg(data.msg)
                }
            },'json');
        }





        /**
         * 切换显示不同任务
         * @param nub
         */
        function showtask(nub) {
            nub=nub-1;
            var html = '';
            if(taskste.length>0){
                var str= taskste[nub];
                setlisthtml2(str);
                $('#Pagination').show();
            }else{
                html += '<li><div style="width:100%;text-align:center;">&nbsp暂无数据</div></li>';
                $(".impowdith").html(html);
                $('#Pagination').hide();
            }
        }

        function setlisthtnml(data,nub) {
            nub=nub-1;
            var html = '';
            if(data.list.length>0){
                $.each(data.list, function (key, value) {
                    data.list[key]['allmoney']=data.list[key]['price']*data.list[key]['number'];
                    data.list[key]['orderid']=date;
                    data.list[key]['real_price']="";
                    if(awz!="0" && awz!=undefined){
                        data.list[key]['awz']=awz;
                    }
                });
                taskste=data.list;
                var str= data.list[0];
                setlisthtml2(str);
                $('#Pagination').show();
            }else{
                html += '<li><div style="width:100%;text-align:center;">&nbsp暂无数据</div></li>';
                $(".impowdith").html(html);
                $('#Pagination').hide();
            }

        }


        function setlisthtml2(str){
            $.each(str, function (key, value) {
                taskste['allmoney']=taskste['price']*taskste['number'];
                if( taskste['orderid']==null){
                    taskste['orderid']=date;
                }
                if(key!='pay_type'){
                    $("input[name='"+key+"']").val(value);
                }else{
                    setpaytype(value);
                }

                if(str.picurl!=null){
                    var picurl=str.picurl;
                    $(".picurl").attr('src',picurl)
                    $(".picurl").show()
                }else{
                    $(".picurl").hide();
                }
                $(".fangwen a").attr("href",str.link);

                if(key=="orderid"){
                    if(value!=null && value!=date){
                        $("#finish").attr("disabled",'true');
                        $("#finish").text("已完成");
                        $("input[name='real_price']").attr("disabled",'true');
                        $("input[name='orderid']").attr("disabled",'true');
                    }else{
                        $("#finish").removeAttr("disabled");
                        $("input[name='real_price']").removeAttr("disabled");
                        $("input[name='orderid']").removeAttr("disabled");
                        $("#finish").text("提交任务");
                    }
                }
            });


        }


        function setpaytype(value){
            $(":radio[value='1']").parents("label").css("color","black");
            $(":radio[value='2']").parents("label").css("color","black");
            $(":radio[value='3']").parents("label").css("color","black");
            $('input[name="pay_type"]').get(value-1).checked = true;
            $(":radio[value='"+value+"']").parents("label").css("color","red")
        }


        $("#finish").click(function () {
            if (on_request) {
                return;
            }
            var id=$("input[name='id']").val();
            var orderid=$("input[name='orderid']").val();
            var real_price=$("input[name='real_price']").val();
            var awz=$("input[name='awz']").val();

            if(orderid==date || orderid==""){
                layer.msg('订单缺少');
                $("input[name='orderid']").focus();
                return ;
            }
            if(orderid.length!=22){
                layer.msg('订单不足22位');
                $("input[name='orderid']").focus();
                return ;
            }
            if(awz==""){
                layer.msg('缺少azw');
                $("input[name='awz']").focus();
                return ;
            }
            if(real_price=="0.00"){
                layer.msg('缺少价格');
                $("input[name='real_price']").focus();
                return ;
            }
            if(id=="" || orderid=="" ||real_price==""){
                layer.msg('缺少参数');
                return ;
            }
            var url = "<?php echo base_url(); ?>Hunter/finnish";
            var postdata = {
                'real_price':real_price,
                'awz':awz,
                'id': id,
                'project': 2,
                'orderid': orderid
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                layer.msg(data.msg);
                if(data.code==0){
                    if((log*1)-1==0){//如果记录的任务全部完成则刷新页面
                        window.location.reload();
                    }
                    addorderid(orderid,awz,id,real_price);
                    log=log-1;
                }
            },'json');
        });


        function addorderid(orderid,awz,id,real_price){
            if(taskste!=""){
                $("#finish").attr("disabled",'true');
                $("#finish").text("已完成");
                $.each(taskste, function (key, value) {
                    $.each(value, function (key2, value2) {
                        if(key2=="id" && value2 ==id){
                            if( taskste[key]['orderid']==null || taskste[key]['orderid']==date){
                                taskste[key]['orderid']=orderid;
                            }
                            if( taskste[key]['awz']==null || taskste[key]['awz']==""){
                                taskste[key]['awz']=awz;
                            }
                            if(( taskste[key]['real_price']==null || taskste[key]['real_price']=="0.00" ||taskste[key]['real_price']=='' ) && real_price!='0.00'&& real_price!=0){
                                taskste[key]['real_price']=real_price;
                            }
                        }
                    });
                });
            }
        }


        $("#replace").click(function () {
            if (on_request) {
                return;
            }

            var postdata=[];
            var id=$("input[name='id']").val();
            var url = "<?php echo base_url(); ?>Hunter/repalcetask/2";
            var epage=$("input[name='epage']").val();
            var newawz="";
       /*     var newawz =prompt("请输入您的awz标示");
            if(newawz=='' ||newawz==null){
                alert("awz不能为空");return;
            }*/
            if(epage==""){
                epage=3;
            }
            page=1;
            var postdata = {
                'page': page,
                'awz': newawz,
                'id': id,
                'epage': epage
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if(data.code==0){
                    $("input[name='epage']").val(data.count);
                    setlisthtnml(data,page);
                    log=data.count;
                    setPagination("Pagination", data.count, page, 1, function (clickPage) {
                        page = parseInt(clickPage) + 1;
                        showtask(page);
                    });
                }else{
                    layer.msg(data.msg)
                }

            },'json');
        });



        $("#throwtask").click(function () {
            if (on_request) {
                return;
            }
            var id=$("input[name='id']").val();
            var url = "<?php echo base_url(); ?>Hunter/throwtask/2";
            var postdata = {
                'id': id
            };
            on_request = true;
            $.post(url, postdata, function (data) {
                on_request = false;
                if(data.code==0){
                    window.location.reload();
                }else{
                    layer.msg(data.msg)
                }
            },'json');
        });



    </script>








    <div class="foods">
        <ul>
            版权所有@2015.
        </ul>
        <dl>
            <a href="" title="返回头部" class="am-icon-btn am-icon-arrow-up"></a>
        </dl>
    </div>




</div>

</div>




</div>


<!--<script src="http://libs.baidu.com/jquery/1.11.1/jquery.min.js"></script>-->
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/polyfill/rem.min.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/polyfill/respond.min.js"></script>
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/amazeui.legacy.js"></script>


<!--[if (gte IE 9)|!(IE)]><!-->
<script src="<?php echo base_url() . 'public/business/'; ?>assets/js/amazeui.min.js"></script>
<!--<![endif]-->



</body>
</html>